<% if !@sprint.nil? %>

<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>


<td id="RightColumn">
<div style="float: right;">
(
<%= popup_link('Burndown', 'show_burndown',
  'width=600,height=400,scrollbars,resizable',
:controller => 'home', :action => 'show_burndown', :id=>@sprint.id) %>
)
</div>


<p class="clear_both"></p>

<h3>Burndown for <%= long_date(Date.today) %></h3>

<% if !@sprint.tasks.empty? %>
<%= start_form_tag(:controller => 'home', :action => 'update_estimates') %>

<div style="float: left;">	
<!--
<% if params['show_inprogress'] %>
(<%= link_to('Show All',
	            {
	              :controller => 'home', :action => 'index',
				:sprint_id => @sprint.id
	            }) %>)
<% else %>
(<%= link_to('Show In-Progress',
	            {
	              :controller => 'home', :action => 'show', 
				:show_inprogress=>1,:sprint_id => @sprint.id
	            }) %>)
<% end %>
-->
</div>
<div style="text-align: right;">
	<input type="submit" name="submit" value="Update Estimates" 
	<% if Date.today > @sprint.stop_date and !params['edit_initial_estimates'] %>
	disabled
	<% end %>
	/>
</div>

<%

counter = 0
sort_header_params = {
  :controller => 'home', :action => 'index'
}
tasks_table = CollectionTableHelper::CollectionTable.new(@tasks,
                                    [:id,
                                     link_to_sort_by('Ticket', 'ticket_id',
                                                     sort_header_params)],
                                    [:name,
                                     link_to_sort_by('Name', 'name',
                                                     sort_header_params)],
                                    :user,
                                    [:initial_estimate,
                                     link_to_sort_by('Initial Est.', 'initial_estimate',
                                                     sort_header_params)],
				                    [:current_estimate,
                                     link_to_sort_by('Current Est.', 'current_estimate',
                                                     sort_header_params)])
tasks_table.data_row_class = ['odd_row', 'even_row']
tasks_table.column_align(:name, 'left')
tasks_table.column_align(:current_estimate, 'center')
tasks_table.column_align(:initial_estimate, 'center')
tasks_table.column_align(:edit, 'right')
tasks_table.column_align(:delete, 'right')

tasks_table.column_modifier(:name) do |t|
  link_to(t.name,
             :controller => 'estimates', :action => 'list', :task_id => t.id)
end

tasks_table.column_modifier(:user) do |t|
	if t.user != nil
		"#{t.user.short_username}"
	end
  
end

tasks_table.column_modifier(:initial_estimate) do |t|
  if params['edit_initial_estimates']
	counter = counter + 1
    "<input tabindex=\"#{counter}\" id=\"tasks_#{t.id}_initial_estimate\" name=\"tasks_#{t.id}_initial_estimate\" type=\"text\" value=\"#{t.initial_estimate}\" size=\"4\"/>"	
  else
    "#{t.initial_estimate} #{sparkline_bitworking_tag t}"
  end
end

tasks_table.column_modifier(:current_estimate) do |t|
  if params['edit_initial_estimates']
	"#{t.current_estimate}"
  else
	counter = counter + 1
    "<input tabindex=\"#{counter}\" id=\"tasks_#{t.id}_current_estimate\" name=\"tasks_#{t.id}_current_estimate\" type=\"text\" value=\"#{t.current_estimate}\" size=\"4\"/>"
  end	
end

%>
<%= tasks_table.build_table %>
<div style="text-align: right;">
<input type="submit" name="submit" value="Update Estimates" 

<% if Date.today > @sprint.stop_date and !params['edit_initial_estimates']  %>
disabled
<% end %>
/>
</div>
<%= end_form_tag %>
<% else %>
<p>No tasks have been assigned to this sprint.  You probably need to <%= link_to('synchronize', :controller => 'tasks', :action => 'sync_with_tickets', :sprint_id=>session[:sprint].id) %> your tickets from your issue tracker.</p>
<% end %>
</td>
</tr>
</table>


<% else %>
  <% if Sprint.find_all.size==0%>
    You need to first create some sprints by first <%= link_to('synchronizing', :controller => 'sprints', :action => 'sync_with_milestones') %> with your issue tracker.
  <% else%>
    Please select a sprint from the left to get started using Rugby!
  <% end%>
<% end %>